package main.java.FSMDE.models;

import java.util.UUID;

import main.java.ERMDE.infrastructure.Func;
import main.java.ERMDE.infrastructure.IterableExtensions;
import main.java.ERMDE.models.ModelCollection;


public class ComponentCollection extends ModelCollection<Component> {

	public ComponentCollection() {
		super();
	}

	public boolean add(Component component) {
		if (this.get(component.getName()) == null) {
			this.items.add(component);
		}
		return false;
	}

	public Component get(UUID id) {
		return IterableExtensions.firstOrDefault(this.items,
				new Func<Component, String, Boolean>() {
					@Override
					public Boolean execute(Component item, String id) {
						return item.getId().toString().equals(id);
					}
				}, id.toString());
	}

	@Override
	protected Component createItemInstance(String componentName) {
		return Component.create(componentName, ComponentType.Generic);
	}

	public void remove(Component component) {
		this.items.remove(component);
	}

	public boolean contains(Component component) {
		return this.items.contains(component);
	}

}
